package com.cy.pj.sys.controller;

import com.cy.pj.common.pojo.SysUser;
import com.cy.pj.common.pojo.SysUserMenu;
import com.cy.pj.common.util.ShiroUtils;
import com.cy.pj.sys.service.SysMenuService;
import org.apache.ibatis.annotations.Mapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.PrivateKey;
import java.util.List;

/**
 * 通过这个Controller处理所有的页面请求
 */
@Controller
public class PageController {
//    @RequestMapping("/menu/menu_list")
//    public String doMenuUI(){
//        return "sys/menu_list";
//    }
@RequestMapping("/doLoginUI")
public String doLoginUI(){
    return "Login";
}
    @RequestMapping("/{module}/{moduleUI}")
    public String doUserUI(@PathVariable String moduleUI){
        return "sys/"+moduleUI;
    }
    /**返回首页页面*/
    @Autowired
    private SysMenuService sysMenuService;
    @GetMapping("/doIndexUI")
    public String doIndexUI(Model model){
        SysUser user=(SysUser) SecurityUtils.getSubject().getPrincipal();
        String loginUser=user.getUsername();//假设这是登录用户
      //  String loginUser="Steven";//假设这是登录用户
        model.addAttribute("username", loginUser);


        List<SysUserMenu> userMenus=
                sysMenuService.findUserMenusByUserId(user.getId());
        model.addAttribute("userMenus",userMenus);
        System.out.println("userMenus="+userMenus);
        return "starter";
    }
    @GetMapping("/doPageUI")//分页返回
    public String doPageUI(){
        return "common/page";
    }




}